package us.gaaoc.framework.webapp.backingbeans.admin;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.faces.application.FacesMessage;
import javax.faces.component.UISelectItem;
import javax.faces.component.html.HtmlSelectOneListbox;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.hibernate.Hibernate;
import org.springframework.transaction.annotation.Transactional;

import us.gaaoc.framework.model.CaseRecord;
import us.gaaoc.framework.model.CaseRecordIdExternalCaseRecordNumber;
import us.gaaoc.framework.model.CaseRecordStatus;
import us.gaaoc.framework.model.DocumentStatus;
import us.gaaoc.framework.model.Documents;
import us.gaaoc.framework.model.OrgParticipants;
import us.gaaoc.framework.model.Person;
import us.gaaoc.framework.model.PersonParticipants;
import us.gaaoc.framework.util.LocalCaseInformation;
import us.gaaoc.framework.util.io.FileUtility;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * 
 * @author hea
 * @date Apr 19, 2006
 * @version: GAJE 1.5
 * 
 */
public class CaseDetailsPage extends BaseBackingBean {

	/**
	 * properties
	 */
	private CaseRecord caseRecord;

	private String filerName;

	private Date courtDate;
	/**
	 * Data Models for the personParticipants
	 */
	private DataModel initiatingPartyPersonModel;

	private DataModel defendentPartyPersonModel;

	private DataModel witnessPersonModel;

	private DataModel plantiffsAttorneyModel;

	private DataModel defendentsAttorneyModel;

	private DataModel initiatingPartyOrganizationDataModel;

	private DataModel documentsModel;

	private Logger LOG = Logger.getLogger(CaseDetailsPage.class);

	private String caseCaption;

	private List<Documents> documentList;

	private String jurisdiction;
	
	private String OCSSCaseNumber;
	
	private String courtCaseNumber;
	
	private String uuid;
	
	private String status;
	
	private HtmlSelectOneListbox caseRecordStatusDescriptionUI;
	
	private HtmlSelectOneListbox documentStatusDescriptionUI;
	
	private boolean renderDocumentStatusListBox;
	
	private String docTitle;
	
	/*
	 * List of Imported Documents
	 */
	private List<Documents> importedDocumentsList;
	private DataModel importedDocumentsModel;
	
	/*
	 * List of Uploaded Documents
	 */
	private List<Documents> uploadedDocumentsList;
	private DataModel uploadedDocumentsModel;
	
	private String formReceivedCaseRecordUuid;
		
	private String newOcssCaseNumber;

	private String courtUuid;
	
	/**
	 * This is used for the confirmation box to delete a case
	 */
	private String confirmBox;
	
	/**
	 * Constructor
	 *
	 */
	public CaseDetailsPage() {
		courtUuid = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("courtUuid");
		confirmBox = "";
		this.loadData();
	}

	/**
	 * This method loads the data from the database for the particular 
	 * filing.
	 *
	 */
	@SuppressWarnings("unchecked")
	private void loadData() {
		/**
		 * A user is presented with a list box of case record status descriptions
		 */
		List<String> caseRecordStatusDescriptionList = new ArrayList<String>();
		caseRecordStatusDescriptionList = this.getModelFacade().getCaseRecordStatusDescriptionList();
		this.caseRecordStatusDescriptionUI = new HtmlSelectOneListbox();
		for(String caseRecordStatusDescription :caseRecordStatusDescriptionList){
			//For each of the case record status description get corresponding code 			
			//and use these pairs as objects and labels 
			//to create UISelectItem uiItems to populate the list box
			SelectItem item = new SelectItem(new String(caseRecordStatusDescription));
			UISelectItem uiItem = new UISelectItem();
			uiItem.setValue(item);
			this.caseRecordStatusDescriptionUI.getChildren().add(uiItem);
		}
		/**
		 * A user is presented with a list box of document status descriptions
		 * when clicked on the change status command link 
		 */
		List<String> documentStatusDescriptionList = new ArrayList<String>();
		documentStatusDescriptionList = this.getModelFacade().getDocumentStatusDescriptionList();
		this.documentStatusDescriptionUI = new HtmlSelectOneListbox();
		for(String documentStatusDescription :documentStatusDescriptionList){
			SelectItem item = new SelectItem(new String(documentStatusDescription));
			UISelectItem uiItem = new UISelectItem();
			uiItem.setValue(item);
			this.documentStatusDescriptionUI.getChildren().add(uiItem);
		}
		
		
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		
		String caseUuid = (String) sessionMap.get("caseUuid");
		CaseRecord c = (CaseRecord) this.getModelFacade().findCaseRecordById(
				caseUuid, courtUuid);
		String docTitle = (String) sessionMap.get("docTitle");
		
		//Uncommented to fix issue:
		//  b7006e6c-695c-11dd-945f-00301b45ff56
		Hibernate.initialize(c.getPersonParticipants());
		Hibernate.initialize(c.getOrgParticipants());
		Hibernate.initialize(c.getDocuments());
		//---------------------

		try {
			this.setJurisdiction(LocalCaseInformation.getJurisdiction(courtUuid));
		} catch (Exception e) {
			e.printStackTrace();
		}
 	
		List<PersonParticipants> pParticipantsList = c.getPersonParticipants();
		List<OrgParticipants> oParticipantsList = c.getOrgParticipants();		

		List initiatingPartyOrganizationList = new ArrayList();

		// for initiating party person list
		List initiatingPartyPersonList = new ArrayList();

		// for defendant party person list
		List defendentPartyPersonList = new ArrayList();

		// for witness person list
		List witnessPersonList = new ArrayList();

		// for plantiff's Attorneys
		List plantiffsAttorneyList = new ArrayList();

		// for defendent's Attorneys
		List defendentsAttorneyList = new ArrayList();

		for (OrgParticipants o : oParticipantsList) {
			if (o.getRelationship().getCode()== 1 )
				initiatingPartyOrganizationList.add(o);
		}

		for (PersonParticipants o : pParticipantsList) {
			if (o.getRelationship().getCode() == 1)
				initiatingPartyPersonList.add(o);
			else if (o.getRelationship().getCode() == 2)
				defendentPartyPersonList.add(o);
			else if (o.getRelationship().getCode() == 3)
				witnessPersonList.add(o);
			else if (o.getRelationship().getCode() == 4)
				plantiffsAttorneyList.add(o);
			else if (o.getRelationship().getCode() == 5)
				defendentsAttorneyList.add(o);
			else if (o.getRelationship().getCode() == 6) {
				Person filer = o.getPerson();
				this.setFilerName(filer.getFirstName() + " "
						+ filer.getMiddleName() + " " + filer.getLastName());
			}
		}

		initiatingPartyOrganizationDataModel = new ListDataModel();
		initiatingPartyOrganizationDataModel
				.setWrappedData(initiatingPartyOrganizationList);

		initiatingPartyPersonModel = new ListDataModel();
		initiatingPartyPersonModel.setWrappedData(initiatingPartyPersonList);

		defendentPartyPersonModel = new ListDataModel();
		defendentPartyPersonModel.setWrappedData(defendentPartyPersonList);

		witnessPersonModel = new ListDataModel();
		witnessPersonModel.setWrappedData(witnessPersonList);

		defendentsAttorneyModel = new ListDataModel();
		defendentsAttorneyModel.setWrappedData(defendentsAttorneyList);

		plantiffsAttorneyModel = new ListDataModel();
		plantiffsAttorneyModel.setWrappedData(plantiffsAttorneyList);
		
		
		List<Documents> pdfList = new ArrayList<Documents>();
		List<Documents>iDocs = new ArrayList<Documents>();
		List<Documents>eDocs = new ArrayList<Documents>();
		 
		/*for (Documents doc : c.getDocuments()){
			if (doc.getPhysicalType().equalsIgnoreCase("pdf"))
				pdfList.add(doc);				
		}*/
		pdfList = this.getModelFacade().getPDFDocuments(caseUuid);
		for(Documents document : pdfList) {
			int docStatusCode = document.getStatus().getCode();
			if(docStatusCode == 2) { // Imported
				iDocs.add(document);
			/* Commented out below to ensure that all 
			 * documents are shown on the screen.  May need
			 * to be updated at a later point to be more
			 * selective again.
			 */
			/*
			}
			else if((docStatusCode == 6)
					|| (docStatusCode == 7)
					|| (docStatusCode == 8) //signedByClerk
					|| (docStatusCode == 9)
					|| (docStatusCode == 10)
					|| (docStatusCode == 11)
					|| (docStatusCode == 12)
					|| (docStatusCode == 15)) {
			*/
			} else if (docStatusCode !=2) { // Not imported
				eDocs.add(document);
			}
		}
		
		this.setImportedDocumentsList(iDocs);
		this.setUploadedDocumentsList(eDocs);
		this.setDocumentList(pdfList);		

		documentsModel = new ListDataModel();		
		importedDocumentsModel = new ListDataModel();
		uploadedDocumentsModel =  new ListDataModel();
		documentsModel.setWrappedData(this.getDocumentList());
		importedDocumentsModel.setWrappedData(this.getImportedDocumentsList());
		uploadedDocumentsModel.setWrappedData(this.getUploadedDocumentsList());

		this.setCaseRecord(c);
		// set court date
		this.setCourtDate(this.getModelFacade().findCourtDate(
				this.getCaseRecord().getUuid()));
		// set case caption
		if (!initiatingPartyOrganizationList.isEmpty()) {
			String initiatingPartyOrgName = ((OrgParticipants) initiatingPartyOrganizationList
					.get(0)).getOrganizations().getName();
			if (!defendentPartyPersonList.isEmpty()) {
				Person defendent = ((PersonParticipants) defendentPartyPersonList
						.get(0)).getPerson();
				String defendentName = defendent.getFirstName() + " "
						+ defendent.getMiddleName() + " "
						+ defendent.getLastName();
				this.setCaseCaption(initiatingPartyOrgName + " vs "
						+ defendentName);
			}
		}
		
		//set OCSS case number
		List<CaseRecordIdExternalCaseRecordNumber> externalCaseIds = 
		    this.getModelFacade().findExternalCaseRecordNumbers(caseUuid);
		if (!externalCaseIds.isEmpty()) {
		    // TODO Need to have types to classify the external 
		    // identifiers
		    CaseRecordIdExternalCaseRecordNumber externalCaseId = externalCaseIds.get(0);
		    String externalCaseNumber = externalCaseId.getExternalCaseRecordNumber();
		    this.setOCSSCaseNumber(externalCaseNumber);
		}
		
				
		//set court case number(docketID)
		String docketID = c.getCaseTrackingId();
		this.setCourtCaseNumber(docketID);
		
		//set uuid 
		String uuid = c.getUuid();
		this.setUuid(uuid);
		
		//set status
		String status = c.getStatus().getDescription();
		this.setStatus(status);
		
		this.docTitle = docTitle;
	}
	
	/**
	 * This method updates the OCSS case number for the case
	 */
	public String updateOcssCaseNumber() {
		// set OCSS case number
		List<CaseRecordIdExternalCaseRecordNumber> externalCaseIds = this
				.getModelFacade().findExternalCaseRecordNumbers(
						caseRecord.getUuid());
		if (!externalCaseIds.isEmpty()) {
			CaseRecordIdExternalCaseRecordNumber externalCaseId = externalCaseIds
					.get(0);
			externalCaseId.setExternalCaseRecordNumber(newOcssCaseNumber);
			String externalCaseNumber = externalCaseId
					.getExternalCaseRecordNumber();
			this.setOCSSCaseNumber(externalCaseNumber);
			
			this.getModelFacade().updateExternalCaseNumber(caseRecord.getUuid(), newOcssCaseNumber);
		} else {
			this.getModelFacade().insertIntoCaseRecordIdExternalCaseRecordNumber(caseRecord,newOcssCaseNumber, this.getModelFacade().findOrganizationById(courtUuid));
			
			List<CaseRecordIdExternalCaseRecordNumber> externalIds = this
					.getModelFacade().findExternalCaseRecordNumbers(
							caseRecord.getUuid());
			
			CaseRecordIdExternalCaseRecordNumber externalCaseId = externalIds
					.get(0);
			externalCaseId.setExternalCaseRecordNumber(newOcssCaseNumber);
			String externalCaseNumber = externalCaseId
					.getExternalCaseRecordNumber();
			this.setOCSSCaseNumber(externalCaseNumber);
		}

		return OCSSCaseNumber;
	}
	
	/**
	 * Deletes the case
	 * @return
	 */
	public String deleteCase() {
		if (confirmBox.equals("deleteCase")) {
			this.getModelFacade().deleteCaseRecord(caseRecord.getUuid(),
					courtUuid);
			return back();
		}
		else{
			FacesContext.getCurrentInstance().addMessage("menu1:deleteButton", new FacesMessage("The case will not be deleted"));
			return null;
		}
	}
	
	@Transactional
	public String deleteDocument() {
		Map requestMap = this.getFacesContext().getExternalContext()
				.getRequestParameterMap();
		String docUuid = (String) requestMap.get("uuid");
		Documents d = (Documents) this.getModelFacade().getSession().get(Documents.class,docUuid);
		if(d != null)
			this.getModelFacade().enableDocDeleteFlag(d);
			this.getModelFacade().deleteDocument(d);
		return "";
	}
	
	
	/**
	 * Takes you to the edit participants page
	 * @return navigation rule to edit the participants
	 */
	public String editParticipants(){
		
		return "editParticipants";
	}
	
	/**
	 * Takes you to the  update parties page
	 * @return navigation rule to edit the parties
	 */
	public String updateParties(){
		
		return "updateParties";
	}
	
	/**
	 * This method navigates user to the import filing page.
	 * @return String
	 */
	public String gotoImportFiling() {
		return "gotoImportFiling";
	}

	/**
	 * This method navigates user to the reject filing page.
	 * @return String
	 */
	public String gotoRejectFiling() {
		return "gotoRejectFiling";
	}

	/**
	 * This method navigates user to the previous page.
	 * @return
	 */
	public String back() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		String fromPage = (String) sessionMap.get("from");
		sessionMap.remove("from");
		sessionMap.remove("caseUuid");

		if (fromPage.equalsIgnoreCase("ChildEnforcementCaseTypePage")) {
			return "childEnforcement";
		} else if (fromPage.equalsIgnoreCase("ReceivedFilingPage")) {
			return "received";
		} else if (fromPage.equalsIgnoreCase("RejectedFilingPage")) {
			return "rejected";
		} else if (fromPage.equalsIgnoreCase("ImportedFilingPage")) {
			return "imported";
		} else if (fromPage.equalsIgnoreCase("DisposedFilingPage")) {
			return "disposed";
		} else if (fromPage.equalsIgnoreCase("TransmissionErrorFilingPage")) {
			return "transmissionError";
		} else if (fromPage.equalsIgnoreCase("ServedFilingPage")) {
			return "served";
		} else if (fromPage.equalsIgnoreCase("NonServedFilingPage")) {
			return "served";
		} else if (fromPage.equalsIgnoreCase("NewFilingPage")) {
			return "newFiling";
		} else if (fromPage.equalsIgnoreCase("AppellateCaseTypePage")){
			return "appellate";
		} else if (fromPage.equalsIgnoreCase("CivilCaseTypePage")){
			return "civil";
		} else if (fromPage.equalsIgnoreCase("MainPage")){
			return "adminHome";
		} else if (fromPage.equalsIgnoreCase("searchPage")){
			sessionMap.put("from", "adminChildEnforcementCaseTypePage");
			return "searchPage";
		}else
			return "";
	}
	
	/**
	 * Getter for property courtDate
	 * @return courtDate
	 */
	public Date getCourtDate() {
		return courtDate;
	}

	/**
	 * Setter for property courtDate
	 * @param courtDate
	 */
	public void setCourtDate(Date courtDate) {
		this.courtDate = courtDate;
	}

	/**
	 * @param initiatingPartyOrganizationDataModel
	 *            The initiatingPartyOrganizationDataModel to set.
	 */
	public void setInitiatingPartyOrganizationDataModel(
			DataModel initiatingPartyOrganizationDataModel) {
		this.initiatingPartyOrganizationDataModel = initiatingPartyOrganizationDataModel;
	}

	/**
	 * @return Returns the caseRecord.
	 */
	public CaseRecord getCaseRecord() {
		return caseRecord;
	}

	/**
	 * Setter for property caseRecord
	 * @param caseRecord
	 */
	public void setCaseRecord(CaseRecord caseRecord) {
		this.caseRecord = caseRecord;
	}

	/**
	 * Getter for property filerName
	 * @return filerName
	 */
	public String getFilerName() {
		return filerName;
	}

	/**
	 * Setter for property filerName
	 * @param filerName
	 */
	public void setFilerName(String filerName) {
		this.filerName = filerName;
	}

	/**
	 * Getter for property defendentPartyPersonModel
	 * @return defendentPartyPersonModel
	 */
	public DataModel getDefendentPartyPersonModel() {
		return defendentPartyPersonModel;
	}

	/**
	 * Setter for property defendentPartyPersonModel
	 * @param defendentPartyPersonModel
	 */
	public void setDefendentPartyPersonModel(DataModel defendentPartyPersonModel) {
		this.defendentPartyPersonModel = defendentPartyPersonModel;
	}

	/**
	 * Getter for property defendentsAttorneyModel
	 * @return defendentsAttorneyModel
	 */
	public DataModel getDefendentsAttorneyModel() {
		return defendentsAttorneyModel;
	}

	/**
	 * Setter for property defendentsAttorneyModel
	 * @param defendentsAttorneyModel
	 */
	public void setDefendentsAttorneyModel(DataModel defendentsAttorneyModel) {
		this.defendentsAttorneyModel = defendentsAttorneyModel;
	}

	/**
	 * Getter for property initiationgPartyPersonModel
	 * @return initiatingPartyPersonModel
	 */
	public DataModel getInitiatingPartyPersonModel() {
		return initiatingPartyPersonModel;
	}

	/**
	 * Setter for property initiatingPartyPersonmodel
	 * @param initiatingPartyPersonModel
	 */
	public void setInitiatingPartyPersonModel(
			DataModel initiatingPartyPersonModel) {
		this.initiatingPartyPersonModel = initiatingPartyPersonModel;
	}

	/**
	 * Getter for property initiatingPartyOrganizationDataModel
	 * @return initiatingPartyOrganizationDataModel
	 */
	public DataModel getInitiatingPartyOrganizationDataModel() {
		return initiatingPartyOrganizationDataModel;
	}

	/**
	 * Getter for property witnessPersonModel
	 * @return
	 */
	public DataModel getWitnessPersonModel() {
		return witnessPersonModel;
	}

	/**
	 * Setter for property witnessPersonModel
	 * @param witnessPersonModel
	 */
	public void setWitnessPersonModel(DataModel witnessPersonModel) {
		this.witnessPersonModel = witnessPersonModel;
	}

	/**
	 * Getter for property plantiffsAttorneyModel
	 * @return plantiffsAttorneyModel
	 */
	public DataModel getPlantiffsAttorneyModel() {
		return plantiffsAttorneyModel;
	}

	/**
	 * Setter for property plantiffsAttorneyModel
	 * @param plantiffsAttorneyModel
	 */
	public void setPlantiffsAttorneyModel(DataModel plantiffsAttorneyModel) {
		this.plantiffsAttorneyModel = plantiffsAttorneyModel;
	}

	/**
	 * Getter for property documentsModel
	 * @return documentsModel
	 */
	public DataModel getDocumentsModel() {
		return documentsModel;
	}

	/**
	 * Setter for property documentsModel
	 * @param documentsModel
	 */
	public void setDocumentsModel(DataModel documentsModel) {
		this.documentsModel = documentsModel;
	}

	/**
	 * Getter for property caseCaption
	 * @return caseCaption
	 */
	public String getCaseCaption() {
		return caseCaption;
	}

	/**
	 * Setter for property caseCaption
	 * @param caseCaption
	 */
	public void setCaseCaption(String caseCaption) {
		this.caseCaption = caseCaption;
	}

	/**
	 * This method browse the clicked PDF file
	 * @return String
	 */
	public String viewFile() {
		Map requestMap = this.getFacesContext().getExternalContext()
				.getRequestParameterMap();
		FacesContext context = this.getFacesContext();
		HttpServletResponse resp = (HttpServletResponse) FacesContext
				.getCurrentInstance().getExternalContext().getResponse();
		String docTitle = (String) requestMap.get("title");

		byte[] docContent = null;
		for (Documents doc : this.getDocumentList()) {
			if (doc.getTitle().equalsIgnoreCase(docTitle)) {
				docContent = doc.getContent();
				break;
			}
		
		}
		
		String ret = "stay";
		
		try {
			ret = FileUtility.streamReportToBrowser(resp, docTitle, docContent);
		} catch (IOException e) {
			LOG.error("Error in CaseDetailPage.viewFile() method: " + e);
			// throw e;
		}
		if(ret.equals("stay")) context.responseComplete();
		return ret;
	}
	
	/**
	 * This method browse the clicked PDF file
	 * 
	 * @return String
	 */
	public String viewDataFile() {
		HttpServletResponse resp = (HttpServletResponse) FacesContext
				.getCurrentInstance().getExternalContext().getResponse();

		String docTitle = caseRecord.getUuid();

		String s = FileUtility.getDataFilePath() + "/" + 
			caseRecord.getCourtUuid() + "/" + 
			caseRecord.getInstantiationDateTime().getYear() + "/" + 
			caseRecord.getInstantiationDateTime().getMonth() + "/" + 
			docTitle;
		
		byte[] docContent = null;
		try {
			docContent = FileUtility.getBytesFromFile(new File(s));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		String docExtension = ".csv";

		try {
			FileUtility.streamReportToBrowser(resp, docTitle, docContent,
					docExtension);
		} catch (IOException e) {
			LOG.error("Error in CaseDetailPage.viewFile() method: " + e);
			// throw e;
		}
		FacesContext.getCurrentInstance().responseComplete();
		return "stay";
	}
	
	/**
	 * When user clicks on the change status button from the case details page
	 * this method gets invoked. The case for which the case details page refers to 
	 * and the selection of the description of the target status are needed for the update
	 * query 
	 * @return
	 */
	public String updateCaseRecordByStatus(){
		LOG.info("Changing the status of the case record "+this.caseRecord.getUuid());
		if(this.caseRecordStatusDescriptionUI==null){
			System.out.println("Send message of no selection ");
			FacesContext facesContext = FacesContext.getCurrentInstance();
			facesContext.addMessage("menu1:caseRecordStatus", new FacesMessage("Please select a status description!"));
			return "stay";
		}
		CaseRecordStatus crs = new CaseRecordStatus();
		String description = this.caseRecordStatusDescriptionUI.getValue().toString();
		int  code = this.getModelFacade().findCaseRecordStatusCode(description);
		crs.setDescription(description);
		crs.setCode(code);		
		this.getModelFacade().UpdateCaseRecordByStatus(this.caseRecord, crs, courtUuid);
		LOG.info("The new status of case record "+this.caseRecord.getUuid()+" is "+this.caseRecord.getStatus().getDescription());
		//return "adminHome";
		return "childEnforcement";
		
		
	}
	
	/**
	 * 
	 */
	//public String showDocumentStatusListBox(){
	  public String goToChildEnforcementDocumentStatusChangePage(){
		LOG.info("Show the list box of document statuses");
		Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
		String docTitle = (String) requestMap.get("title");
		this.renderDocumentStatusListBox = true;
		this.docTitle = docTitle;
		LOG.info("The file selected for status change is "+docTitle);
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		sessionMap.put("docTitle", docTitle);
		sessionMap.put("caseUuid", this.caseRecord.getUuid());
		LOG.info("Document put on session: "+(String)sessionMap.get("docTitle"));
		return "changeDocumentStatus";
	}
	
	public String updateDocumentStatus(){		
	 	Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		String docTitle = (String)sessionMap.get("docTitle");
		String caseUuid = (String)sessionMap.get("caseUuid");
		LOG.info("Updating the status of docTitle");
		this.docTitle = docTitle;
		this.caseRecord = (CaseRecord) this.getModelFacade().findCaseRecordById(caseUuid, courtUuid);
		//this.renderDocumentStatusListBox = true;
		DocumentStatus ds = new DocumentStatus();
		String description = this.documentStatusDescriptionUI.getValue().toString();
		int  code = this.getModelFacade().findDocumentStatusCode(description);
		ds.setDescription(description);
		ds.setCode(code);	
		for (Documents doc : this.getDocumentList()) {
			if (doc.getTitle().equalsIgnoreCase(docTitle)) {
				this.getModelFacade().UpdateDocumentByStatus(doc.getUuid(), ds);				
				return "goToCaseDetailsPage";
			}
		}
		//this.getModelFacade().UpdateDocumentByStatus(this.caseRecord, ds);
		return "goToCaseDetailsPage";
	}
	
	//TODO: Find out if this is used at all... I don't think this is. -Robbie
	public String getParticipants() {
		System.out.println("Inside the getParticipnts method!! The passed uuid is "+this.formReceivedCaseRecordUuid);
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		String uuid = this.formReceivedCaseRecordUuid;
		CaseRecord caseRecord = this.getModelFacade().findCaseRecordById(uuid, courtUuid);
		//List<PersonParticipants> caseRecordParticipants = new ArrayList<PersonParticipants>();
		//this.caseRecordParticipants = caseRecord.getPersonParticipants();
		//int length = this.caseRecordParticipants.size();
		return "goToChildEnforcementParticipantsPage";
	}
	
	
	/**
	 * Getter for property documentList
	 * @return documentList
	 */
	public List<Documents> getDocumentList() {
		return documentList;
	}

	/**
	 * Setter for property documentList
	 * @param documentList
	 */
	public void setDocumentList(List<Documents> documentList) {
		this.documentList = documentList;
	}

	/**
	 * @return the jurisdiction
	 */
	public String getJurisdiction() {
		return jurisdiction;
	}

	/**
	 * @param jurisdiction the jurisdiction to set
	 */
	public void setJurisdiction(String jurisdiction) {
		this.jurisdiction = jurisdiction;
	}

	public String getOCSSCaseNumber() {
		return OCSSCaseNumber;
	}

	public void setOCSSCaseNumber(String caseNumber) {
		OCSSCaseNumber = caseNumber;
	}

	public String getCourtCaseNumber() {
		return courtCaseNumber;
	}

	public void setCourtCaseNumber(String courtCaseNumber) {
		this.courtCaseNumber = courtCaseNumber;
	}

	public HtmlSelectOneListbox getCaseRecordStatusDescriptionUI() {
		return caseRecordStatusDescriptionUI;
	}

	public void setCaseRecordStatusDescriptionUI(
			HtmlSelectOneListbox caseRecordStatusDescriptionUI) {
		this.caseRecordStatusDescriptionUI = caseRecordStatusDescriptionUI;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public HtmlSelectOneListbox getDocumentStatusDescriptionUI() {
		return documentStatusDescriptionUI;
	}

	public void setDocumentStatusDescriptionUI(
			HtmlSelectOneListbox documentStatusDescriptionUI) {
		this.documentStatusDescriptionUI = documentStatusDescriptionUI;
	}

	public boolean isRenderDocumentStatusListBox() {
		return renderDocumentStatusListBox;
	}

	public void setRenderDocumentStatusListBox(boolean renderDocumentStatusListBox) {
		this.renderDocumentStatusListBox = renderDocumentStatusListBox;
	}

	public String getDocTitle() {
		return docTitle;
	}

	public void setDocTitle(String docTitle) {
		this.docTitle = docTitle;
	}

	public List<Documents> getImportedDocumentsList() {
		return importedDocumentsList;
	}

	public void setImportedDocumentsList(List<Documents> importedDocumentsList) {
		this.importedDocumentsList = importedDocumentsList;
	}

	public DataModel getImportedDocumentsModel() {
		return importedDocumentsModel;
	}

	public void setImportedDocumentsModel(DataModel importedDocumentsModel) {
		this.importedDocumentsModel = importedDocumentsModel;
	}

	public List<Documents> getUploadedDocumentsList() {
		return uploadedDocumentsList;
	}

	public void setUploadedDocumentsList(List<Documents> uploadedDocumentsList) {
		this.uploadedDocumentsList = uploadedDocumentsList;
	}

	public DataModel getUploadedDocumentsModel() {
		return uploadedDocumentsModel;
	}

	public void setUploadedDocumentsModel(DataModel uploadedDocumentsModel) {
		this.uploadedDocumentsModel = uploadedDocumentsModel;
	}

	public String getFormReceivedCaseRecordUuid() {
		return formReceivedCaseRecordUuid;
	}

	public void setFormReceivedCaseRecordUuid(String formReceivedCaseRecordUuid) {
		this.formReceivedCaseRecordUuid = formReceivedCaseRecordUuid;
	}
	
	public String getNewOcssCaseNumber() {
		return newOcssCaseNumber;
	}

	public void setNewOcssCaseNumber(String newOcssCaseNumber) {
		this.newOcssCaseNumber = newOcssCaseNumber;
	}

	public String getConfirmBox() {
		return confirmBox;
	}

	public void setConfirmBox(String confirmBox) {
		this.confirmBox = confirmBox;
	}

}